package com.blockchain.front.servlets;

import java.io.IOException;
import java.sql.SQLException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.blockchain.framework.resource.PromptLevel;
import com.blockchain.framework.service.ServiceSession;
import com.blockchain.framework.service.exception.LogicalException;
import com.blockchain.framework.service.exception.ParameterException;
import com.blockchain.front.service.common.UserManage;

public class RegisterTwo extends AbstractFrontServlet {
	private static final long serialVersionUID = 1L;
	@Override
	protected void processPost(final HttpServletRequest request,
			HttpServletResponse response, ServiceSession serviceSession)
			throws Throwable {
		String paypassword=request.getParameter("paypassword");
		String repaypassword=request.getParameter("repaypassword");
		if(!paypassword.equals(repaypassword)){
			getController().prompt(request, response, PromptLevel.ERROR,
					"两次交易密码输入不一致!");
			forwardView(request, response, getClass());
			return;
		}
		UserManage userManage = serviceSession.getService(UserManage.class);
		userManage.addJymm(repaypassword);
		sendRedirect(request,response,getController().getViewURI(request,  RegisterThree.class));
	}
	@Override
	protected void onThrowable(HttpServletRequest request,
			HttpServletResponse response, Throwable throwable)
			throws ServletException, IOException {
		getResourceProvider().log(throwable.getMessage());
		if (throwable instanceof LogicalException
				|| throwable instanceof ParameterException) {
			prompt(request, response, PromptLevel.ERROR, throwable.getMessage());
			forwardView(request, response, getClass());
		} else if (throwable instanceof SQLException) {
			prompt(request, response, PromptLevel.ERROR, "系统繁忙，请稍后再试");
			forwardView(request, response, getClass());
		} else {
			super.onThrowable(request, response, throwable);
		}
	}
}
